spb/satelliteindex
Public
TypeScript 66.5%
Python 30.9%
JavaScript 1.4%
CSS 0.7%
1import { NextResponse } from 'next/server';2import { adminApi, AdminApiError } from '@/lib/admin-api';3import { isAdmin } from '@/lib/admin-auth';45export const dynamic = 'force-dynamic';67/** Enable / disable a connector: body `{ "enabled": boolean }` → FastAPI `/admin/connectors/{name}/enabled`. */8export async function POST(req: Request, ctx: { params: Promise<{ name: string }> }): Promise<Response> {9 if (!(await isAdmin())) return NextResponse.json({ error: { title: 'Unauthorized', status: 401 } }, { status: 401 });10 const { name } = await ctx.params;11 const body = (await req.json().catch(() => null)) as { enabled?: unknown } | null;12 if (!body || typeof body.enabled !== 'boolean') return NextResponse.json({ error: { title: 'Invalid body', detail: '`enabled` must be a boolean', status: 422 } }, { status: 422 });13 try {14 const out = await adminApi.setEnabled(name, body.enabled);15 return NextResponse.json(out.data);16 } catch (e) {17 const status = e instanceof AdminApiError && e.status > 0 ? e.status : 502;18 return NextResponse.json({ error: { title: 'Toggle failed', detail: (e as Error).message, status } }, { status });19 }20}21